#include <stdio.h>
#include <stdlib.h>

#define HALF_BITS_LENGTH 4//4bits
#define FULLMASK 255//1111111
#define LMASK (FULLMASK << HALF_BITS_LENGTH)//11110000
#define RMASK (FULLMASK >> HALF_BITS_LENGTH)//00001111
#define RSET(b, n) (b = ((LMASK & b)| (n)))//
#define LSET(b, n) (b = ((RMASK & b)| ((n) << HALF_BITS_LENGTH)))
#define RGET(b) (RMASK & b)
#define LGET(b) ((LMASK & b) >> HALF_BITS_LENGTH)
#define GRIDW 3




int main(void)
{
	unsigned char b;
	
	for (LSET(b, 1); LGET(b) <= GRIDW * GRIDW; LSET(b, (LGET(b) + 1)))
		for (RSET(b, 1); RGET(b) <= GRIDW * GRIDW; RSET(b, (RGET(b) + 1)))
			if (LGET(b) % GRIDW != RGET(b) % GRIDW)
				printf("A = %d, B = %d\n", LGET(b), RGET(b));
			
	system("pause");
	return 0;
}